// 防抖
export function _debounce(fn, d) {
  var delay = d || 600;
  var timer;
  return function() {
    var th = this;
    var args = arguments;
    if (timer) {
      clearTimeout(timer);
    }
    timer = setTimeout(function() {
      timer = null;
      fn.apply(th, args);
    }, delay);
  };
}
// 节流
export function _throttle(fn, d) {
  var last;
  var timer;
  var interval = d || 600;
  return function() {
    var th = this;
    var args = arguments;
    var now = +new Date();
    if (last && now - last < interval) {
      clearTimeout(timer);
      timer = setTimeout(function() {
        last = now;
        fn.apply(th, args);
      }, interval);
    } else {
      last = now;
      fn.apply(th, args);
    }
  };
}

export function getBase64(file) {// blob转base64字符
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    let imgResult = ''
    reader.readAsDataURL(file)
    reader.onload = function() {
    imgResult = reader.result
    }
    reader.onerror = function(error) {
    reject(error)
    }
    reader.onloadend = function() {
    resolve(imgResult)
    }
  })
}

export const imgUrl = 'https://newapi.shanqueyi.com';//上传图片后给返回的路径加前缀
/*
 * 使用方法
 */

// import { _debounce } from "@u/debounce";
//  add:_debounce(function() {})     不丢this
